/*
 *  Borum, Boolean rule manipulator.
 *  Copyright (C) 2009 Jon Lennersten, Johan Hedin, Daniel Rosenberg
 *
 *  This file is part of Borum.
 *
 *  Borum is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Borum is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Borum.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.mawell.borum;

import javax.swing.*;
import java.util.List;

public class MultiModel {
    DefaultListModel viewListModel = new DefaultListModel();

    List<Term> possibleTerms;
    private List<OperandProperty> possibleProperties;

    public DefaultListModel getViewListModel() {
        return viewListModel;
    }

    public void setViewListModel(DefaultListModel viewListModel) {
        this.viewListModel = viewListModel;
    }

    public List<Term> getPossibleTerms() {
        return possibleTerms;
    }

    public void setPossibleTerms(List<Term> possibleTerms) {
        this.possibleTerms = possibleTerms;
    }

    public void addRuleView(RuleView v) {
        viewListModel.addElement(v);
    }

    public RuleView getView(int selectedIndex) {
        if(viewListModel.size() > 0 && selectedIndex > -1 && selectedIndex < viewListModel.size()) {
            return (RuleView) viewListModel.get(selectedIndex);
        } else {
            return null;
        }
    }

    public void deleteRuleView(int selectedIndex) {
        if(getView(selectedIndex) != null && !getView(selectedIndex).isLocked()) {
          ((RuleView)viewListModel.get(selectedIndex)).setDeleted(true);
        }
    }

    public void setRuleViewName(String s, int selectedIndex) {
        getView(selectedIndex).setName(s);
    }

    public void undeleteRuleView(int selectedIndex) {
        ((RuleView)viewListModel.get(selectedIndex)).setDeleted(false);
    }

    public void setPossibleProperties(List<OperandProperty> possibleProperties) {
        this.possibleProperties = possibleProperties;
    }

    public List<OperandProperty> getPossibleProperties() {
        return possibleProperties;
    }
}
